package com.jc.repository.dict;

import com.google.common.collect.Lists;
import com.jc.base.EnumCode;
import com.jc.utils.Strings;

import java.util.Collections;
import java.util.List;

public enum UserTag implements EnumCode {
    集团用户("hsd");

    private final String code;

    private UserTag(String code){
        this.code = code;
    }

    @Override
    public String code() {
        return code;
    }

    public static UserTag findTagByCode(String param){
        for(UserTag tag : UserTag.values()){
            if(Strings.equalsIgnoreCase(tag.code(),param)){
                return tag;
            }
        }
        throw new IllegalArgumentException("参数["+param+"]未找到匹配的用户标签");
    }

    public static List<UserTag> findTagsByUserTagExtension(String param){
        if(Strings.isBlank(param)){
            return Collections.emptyList();
        }
        final String[] tagArray = Strings.split(param,"\\;");
        List<UserTag> userTags = Lists.newArrayListWithCapacity(tagArray.length);
        for(String tempTag : tagArray){
            UserTag userTag = findTagByCode(tempTag);
            userTags.add(userTag);
        }
        return userTags;
    }

    /**
     * 是否具有指定标签
     */
    public static boolean hasSpecificTag(String extension,UserTag tag){
        List<UserTag> tags = findTagsByUserTagExtension(extension);
        return tags.contains(tag);
    }
}